program main

    integer, parameter :: rk = 8
    print *, linspace(1.0_rk, 2.0_rk, 1)
    print *, linspace(1.0_rk, 2.0_rk, 2)

contains

    !> constructs a vector of n linearly spaced numbers from start to end <br>
    !> 从 start 到 end 构造一个 n 个线性间隔的数字向量
    pure function linspace(start, end, n) result(v)
        real(rk), intent(in) :: start, end
        integer, intent(in) :: n
        real(rk) :: v(max(n, 0))

        real(rk) :: step
        integer :: i

        if (n <= 0) then
            return
        elseif (n == 1) then
            v(1) = start
            return
        end if

        step = (end - start)/(n - 1)
        do concurrent(i=1:n)
            v(i) = start + (i - 1)*step
        end do

    end function linspace

end program main

!   1.0000000000000000     
!   1.0000000000000000        2.0000000000000000